package 简单.翻转二叉树;

import java.util.LinkedList;
import java.util.Queue;
//迭代
//广度优先探索
public class Solution2 {
    public TreeNode invertTree(TreeNode root) {

        Queue<TreeNode> queue = new LinkedList<>();
        if(root == null){
            return null;
        }
        queue.offer(root);
        while (!queue.isEmpty()){
            TreeNode p = queue.poll();
            TreeNode temp;
            temp = p.left;
            p.left = p.right;
            p.right = temp;

            if(p.left!=null){
                queue.offer(p.left);
            }
            if(p.right!=null){
                queue.offer(p.right);
            }

        }
        return root;
    }
}
